#include "CUIManager.h"
#include "CBaseUIObject.h"


CUIManager::CUIManager()
{
	m_bHideUI = false;
}


CUIManager::~CUIManager()
{
	ShutDown();
}


CUIManager* CUIManager::GetInstance()
{
	static CUIManager manager;
	return &manager;
}


void CUIManager::Update(double delta)
{
	for(unsigned int i = 0; i < m_vUIObjects.size(); i++)
	{
		m_vUIObjects[i]->Update(delta);
	}
}


void CUIManager::Render()
{
	if(!m_bHideUI)
	{
		for(unsigned int i = 0; i < m_vUIObjects.size(); i++)
		{
			m_vUIObjects[i]->Render();
		}
	}
}


void CUIManager::StartUp()
{
	m_bHideUI = false;
}


void CUIManager::ToggleUI()
{
	m_bHideUI = !m_bHideUI;
}


void CUIManager::ShutDown()
{
	ClearUI();
}

void CUIManager::AddUIElement(CBaseUIObject* Element)
{
	m_vUIObjects.push_back(Element);
}


void CUIManager::RemoveUIElement(CBaseUIObject* Element)
{
	for(unsigned int i = 0; i < m_vUIObjects.size(); i++)
	{
		if(Element == m_vUIObjects[i])
		{
			//do stuff, i.e. delete or return it
			return;
		}
	}
}


void CUIManager::ClearUI()
{
	while(!m_vUIObjects.empty())
	{
		//MAY WANT TO CHANGE THIS FROM DELETE TO RETURN..... JUST SAYIN'
		delete m_vUIObjects.back();
		m_vUIObjects.pop_back();
	}
	m_vUIObjects.clear();
}